package com.bpm.example.event.other;

import com.bpm.common.util.FlowableEngineUtil;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.flowable.task.api.TaskQuery;
import org.junit.Test;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 终止结束事件(终止结束事件是在主流程中触发的场景)
 */
@Slf4j
public class RunTerminateEndEventProcessDemo extends FlowableEngineUtil {

    @Test
    public void runTerminateEndEventProcessDemo() {
        //加载Flowable配置文件并初始化流程引擎及服务
        initFlowableEngineAndServices("flowable.cfg.xml");
        Map<String,Object> variables=new HashMap<>();
        variables.put("terminationFlag",false);
        //部署流程
        ProcessDefinition processDefinition = deployResource("processes/TerminateEndEventProcess.bpmn20.xml");
        ProcessInstance procInst = runtimeService.startProcessInstanceById(processDefinition.getId(),variables);
        //获取任务
        TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
        List<Task> taskList = taskQuery.list();
        //挨个审批
        taskList.forEach(e->{
            taskService.complete(e.getId());
        });

    }

}
